package com.tancw.cloud.product.service.impl;

import com.tancw.cloud.common.Result;
import com.tancw.cloud.product.entity.Product;
import com.tancw.cloud.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 商品服务实现
 */
@Slf4j
@DubboService
@Service
public class ProductServiceImpl implements ProductService {

    @Override
    public Result<Product> getProductById(Long id) {
        log.info("查询商品: {}", id);
        
        // TODO: 从数据库查询商品
        Product product = new Product();
        product.setId(id);
        product.setProductName("测试商品");
        product.setProductCode("P" + System.currentTimeMillis());
        product.setPrice(BigDecimal.valueOf(99.99));
        product.setStock(100);
        product.setStatus(1);
        product.setCreateTime(LocalDateTime.now());
        
        return Result.success(product);
    }

    @Override
    public Result<Void> deductStock(Long productId, Integer quantity) {
        log.info("扣减库存: productId={}, quantity={}", productId, quantity);
        // TODO: 扣减商品库存
        return Result.success();
    }

    @Override
    public Result<BigDecimal> getProductPrice(Long productId) {
        log.info("获取商品价格: {}", productId);
        // TODO: 从数据库查询商品价格
        return Result.success(BigDecimal.valueOf(99.99));
    }
}